package Thread;

/* 模拟一个银行存款的程序。假设有两个储户都去银行往同一个账户进行存款，
 一次存100，每人存三次。要求储户每存一次钱，账户余额增加100，
 并在控制台输出当前账户的余额。*/
public class Bank implements Runnable {

    int deposit=0;
    int num=0;
    public void run() {

      for(int i=0;i<3;i++){
         save();
      }
    }

    public synchronized void save(){
        deposit+=100;
        num++;
        System.out.println(Thread.currentThread().getName()+"是第"+num+"次存款，账户余额"+deposit+"元");
    }


    public static void main(String[] args) {
       Bank bank=new Bank();
        Thread td1=new Thread(bank,"王力宏");
        Thread td2=new Thread(bank,"周杰伦");
        td1.start();
        td2.start();
    }
}
